<employee title="lover">用Ajax获取title的值

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:30:33
//sansan.xml

<?xml version="1.0" encoding="gb2312" ?>

<employees>

<employee title="Software Engineer"> <name>sansan</name> </employee>

<employee title="Salesperson"> <name>huaisan.wang</name> </employee> <employee title="Salesperson"> <name>hong</name> </employee> </employees>

用Ajax怎样的办法才能提取title的值和name的值

getElementsByTagName("employee")然后呢

求大侠们帮帮菜鸟

感激

getAttribute("title");

感觉还是用JQuery 来解析 XML 比较好一点,也许是我对Jquery用得比较多的原因,jquery:
$.ajax({
url: sansan.xml',
dataType: 'xml',
type: 'GET',
error: function(xml){
alert('error loading XML docuemt'+xml);
},
success: function(xml){
$(xml).find('employee').each(function() {
var title = $(this).attr('title');
var name = $(this).children('name').text();
alert(title);
alert(name);
});
}
});